
import 'dart:convert';
import 'package:flutter_jpf_core/util/data_util.dart';

import 'http_response.dart';

class HttpJSONResponse extends HttpResponse{


  HttpJSONResponse(Function success,Function(HTTPError error,String message) fail,{Function complete}):super(success,fail,complete:complete);


  @override
  bool isResponseSuccess(obj) {
    // TODO: implement isResponseSuccess
    String strObjType = obj.runtimeType.toString().toLowerCase();
    if (strObjType == "string") {
      //防止接口返回""，不额外处理，上层判断
      dynamic jsonObj = jsonDecode(obj);
      if(!DataUtil.isStringEmpty(obj) && jsonObj != null){
        return true;
      }else{
        return false;
      }
    }else if(strObjType.contains("map") || strObjType.contains("list")){
      return true;
    }
    return false;
  }

  @override
  serviceOriginalResponse(obj) {
    // TODO: implement serviceOriginalResponse
    String strObjType = obj.runtimeType.toString().toLowerCase();
    if (strObjType == "string") {
      //防止接口返回""，不额外处理，上层判断
      dynamic jsonObj = jsonDecode(obj);
      if(!DataUtil.isStringEmpty(obj) && jsonObj != null){
        return jsonObj;
      }else{
        return null;
      }
    }else if(strObjType.contains("map") || strObjType.contains("list")){
      return obj;
    }
  }
}